package com.cskaoyan.controller;

import com.cskaoyan.bean.bo.RefundBo;
import com.cskaoyan.bean.bo.ShipBo;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.service.MarketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("admin/order")
public class OrderController {

    @Autowired
    MarketService marketService;

    @RequestMapping("list")
    public BaseRespVo getOrderList(Integer page, Integer limit, String sort, String order,
                                   Integer userId, Integer orderSn, Short[] orderStatusArray){

        Map<String, Object> brandMap = marketService.getOrderList(page, limit, sort, order, userId, orderSn, orderStatusArray);
        return BaseRespVo.ok(brandMap);
    }
    @RequestMapping("detail")
    public BaseRespVo orderDetail(Integer id) {
        Map<String, Object> map = marketService.orderDetail(id);
        return BaseRespVo.ok(map);
    }

    @RequestMapping("ship")
    public BaseRespVo orderRefund(@RequestBody ShipBo shipBo){
        int ship = marketService.ship(shipBo);
        BaseRespVo baseRespVo = new BaseRespVo();
        if (ship != 1 ){
            baseRespVo.setErrno(1);
            baseRespVo.setErrmsg("发货失败");
        }
        return BaseRespVo.ok();
    }

    @RequestMapping("refund")
    public BaseRespVo orderShip(@RequestBody RefundBo refundBo){
        int refund = marketService.refund(refundBo);
        BaseRespVo baseRespVo = new BaseRespVo();
        if (refund != 1 ){
            baseRespVo.setErrno(1);
            baseRespVo.setErrmsg("退款失败");
        }
        return BaseRespVo.ok();
    }


}
